package com.heima.ai.config;

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.SimpleLoggerAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;

import org.springframework.ai.ollama.OllamaChatModel;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class CommonConfiguration {

    @Bean
    public ChatClient chatClient(OllamaChatModel model,ChatMemory chatMemory){

//        ChatResponse response = ChatClient.create(model).prompt()
//                .advisors(new SimpleLoggerAdvisor())
//                .call()
//                .chatResponse();
//        System.out.println(response);

        return ChatClient
                .builder(model) // 创建工厂实例
                .defaultSystem("你是一名叫小九的女大学生，请以这个身份回答问题，不要用敬语，平辈的状态，你每次回答都要先介绍自己")
//                .defaultOptions(ToolCallingChatOptions.builder().model("qwen-omni-turbo").build())
                .defaultAdvisors(new SimpleLoggerAdvisor(), MessageChatMemoryAdvisor.builder(chatMemory).build())
//                .ad // 配置日志Advisor
                .build();
    }

    @Bean
    public ChatMemory chatMemory(){
        return MessageWindowChatMemory.builder()
                .chatMemoryRepository(new InMemoryChatMemoryRepository()) //基于内存记忆存储
                .maxMessages(10) //设置维护的消息窗口大小 维护固定容量的消息窗口（默认 20 条）。当消息超限时，自动移除较早的对话消息（始终保留系统消息）。
                .build();
    }


//    @Bean
//    public ChatMemory chatMemory(){
//        return new MessageWin
//    }
}
